package com.leyantech.ecp.agenx.common.sender;

import com.leyantech.chaos.kafka.KafkaProducerStringClient;
import com.leyantech.ecp.agenx.common.config.MessageAddress;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import io.vertx.core.Future;
import io.vertx.core.impl.VertxInternal;

/**
 * @author eahau, {@literal <eahau@foxmail.com>}
 * @date 2022-11-24.
 */
@Singleton
public class Dispatcher extends KafkaSender {

  @Inject
  public Dispatcher(VertxInternal vertx, KafkaProducerStringClient producer) {
    super(vertx, producer, "dispatcher.message.topic");
  }

  /**
   * 发送给 connector 上的所有在线客服.
   */
  public Future<Void> sendToAll(String message) {
    return send(MessageAddress.ALL, message);
  }

  /**
   * 发送给 connector 上的指定店铺的所有在线客服.
   */
  public Future<Void> sendToStoreConnector(String sid, String message) {
    return send(sid, message);
  }

  /**
   * 发送给 connector 上的指定店铺的在线客服.
   */
  public Future<Void> sendToConnector(String sid, String assistantId, String message) {
    return send(String.join(".", sid, assistantId), message);
  }

}
